package cn.edu.cdp.dao;

import cn.edu.cdp.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.Vector;

@Repository
public interface StudentDao {
    @Select("select s.student_id studentId, s.name, s.sex, s.birthday, s.cee_score ceeScore, " +
            "s.nation, s.native_place nativePlace, s.resume, s.profile, s.major_id majorId, m.name majorName " +
            "from student s left join major m on s.major_id = m.major_id")
    List<Student> allStudent();

    @Select("select s.student_id studentId, s.name, s.sex, s.birthday, s.cee_score ceeScore, " +
            "s.nation, s.native_place nativePlace, s.resume, s.profile, s.major_id majorId, m.name majorName " +
            "from student s, major m where s.major_id = m.major_id and s.student_id=#{studentId}")
    Student basicInfo(String studentId);

    @Select("select c.semester, c.name, s.score, c.credit from study s, student stu, course c " +
            "where s.student_id=stu.student_id and s.course_id=c.course_id and stu.student_id=#{studentId}")
    List<Map<String, Object>> scoreList(String studentId);

    @Insert("insert into student (student_id, name, sex, birthday, cee_score, nation, native_place, resume, profile, major_id) " +
            "values (#{studentId}, #{name}, #{sex}, #{birthday}, #{ceeScore}, #{nation}, #{nativePlace}, #{resume}, #{profile}, #{majorId})")
    void insert(Student student);

    @Update("update student set name=#{name}, sex=#{sex}, birthday=#{birthday}, cee_score=#{ceeScore}, nation=#{nation}, " +
            "native_place=#{nativePlace}, resume=#{resume}, profile=#{profile}, major_id=#{majorId} where student_id=#{studentId}")
    void update(Student student);

    @Delete("delete from student where student_id=#{studentId}")
    void deleteById(String studentId);
}
